package com.example.lvsuo.Execl.cw;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
@EnableConfigurationProperties(ModelApplication.class)
@RestController
public class QrcodeController {
    @Autowired
    ModelApplication  mo;

    /**
     * 根据 url 生成 带有logo二维码
     */
    @RequestMapping(value = "/createLogoQRCode")
    public void createLogoQRCode(HttpServletResponse response, String url) throws Exception {
        ServletOutputStream stream = null;

        //二次调用的时候把支付状态更改为 false   即可重新扫码支付
        mo.setZhifu("false");
        try {
            stream = response.getOutputStream();
            String logoPath ="D:\\学习软件\\IDEA\\lvsuo\\src\\main\\resources\\static\\logo.png";
            //使用工具类生成二维码
            QRCodeUtil.encode(url, logoPath, stream, true);
        } catch (Exception e) {
            e.getStackTrace();
        } finally {
            if (stream != null) {
                stream.flush();
                stream.close();
            }
        }
    }


}